console.log(2)

window.onload=function(){
   console.log('onload')
}
new Promise().finally

// function deepClone(obj){
//   let cloneObj = {}
//   const keys = Object.keys(obj)

//   keys.forEach((item) => {

//     if (Array.isArray(obj[item])) {
//         cloneObj[item] = obj[item].map((it) => deepClone(it))
//     } else if (typeof obj[item] === 'object') {
//         cloneObj[item] = deepClone(obj[item])
//     } else {
//       cloneObj[item] = obj[item]
//     }

//   })
//   return cloneObj
// }

// let obj={obj1:{obj2:{name:'df',arr:[1,2,3,4]}}}
// let clone=deepClone(obj)
// console.log(clone)
// console.log(obj.obj.cobj===clone.obj.cobj)
// let obj = { name: 'dsfs' }
// for (let item of obj) {
//    console.log(item)
// }
// function flatArr() {
//    console.log(this)
// }
// let fn = flatArr.bind({ name: 'hellow' })
// fn.call({ name: 'nihao' })

// require(‘vue’)
// vue.a=5
// import'vue'

let a;
function bibao() {
   if (!a) {
      a = () => {
         console.log(this)
      }
   }
   return a
}
let fn1 = bibao()
fn1() // window
let fn2 = bibao.call({ name: 'dfs' })
fn2() // {name:'dfs'}
let obj1 = {
   form: [
      {propId:'location',value:'',label:'工作地点'},
      {propId:'team',value:'',label:'工作地点'},
      {propId:'education',value:'',label:'工作地点'},
      {propId:'educationalBackground',value:'',label:'工作地点'}
   ]
}
console.log(4)


const Internal=Symbol('internal')
function produce(targetState,producer){
   const proxyState=toProxy(targetState)
    producer(proxyState)
    return proxyState[Internal].change?proxyState[Internal].copyState:proxyState[Internal].targetState
}
function toProxy(targetState,callBack=()=>{}){
  const internal={
    targetState,
    keyToProxy:{},
    change:false,
    copyState:createCopy(targetState)
  }
  return new Proxy(targetState,{
     get(_,key){
         if(key===Internal){
            return internal
         }
         if(key in internal.keyToProxy){
            return internal.keyToProxy[key]
         }else{
           const value= targetState[key]
            if(typeof value==='object'){
                 internal.keyToProxy[key]=toProxy(value,()=>{
                  internal.change=true
                  const proxyChild = internal.keyToProxy[key];
                  internal.copyState[key]=proxyChild[Internal].copyState
                  callBack()
                 })
            }
         }
         return  internal.keyToProxy[key]
     },
     set(_,key,value){
        internal.change=true
        internal.copyState[key]=value
        callBack()
        return true
     }
  })
}
function createCopy(targetState){
  if(Array.isArray(targetState)){
   return [...targetState]
  }else{
   return {...targetState}
  }
}